﻿Imports System.Data.SqlServerCe
Imports System.IO

Public Class frmMain

    Private Sub SluitenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SluitenToolStripMenuItem.Click
        Dim strBoodschap As String = "Ben je zeker dat je wilt afsluiten?"
        Dim strTitel As String = "Proventi Voorraadbeheer"
        Dim intAntwoord As DialogResult

        intAntwoord = MessageBox.Show(strBoodschap, strTitel, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

        If intAntwoord = Windows.Forms.DialogResult.Yes Then
            Me.Close()
        End If

    End Sub

    Private Sub ProductenBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductenBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ProductenBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DtsVoorraad)

    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DtsVoorraad.Bewegingen' table. You can move, or remove it, as needed.
        Me.BewegingenTableAdapter.Fill(Me.DtsVoorraad.Bewegingen)
        'TODO: This line of code loads data into the 'DtsVoorraad.Producten' table. You can move, or remove it, as needed.
        Me.ProductenTableAdapter.Fill(Me.DtsVoorraad.Producten)

    End Sub

    Private Sub ProductenDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles ProductenDataGridView.CellFormatting
        If ProductenDataGridView.Columns(e.ColumnIndex).Name = "Productfoto" Then
            Dim rij As DataGridViewRow = Me.ProductenDataGridView.Rows(e.RowIndex)
            ' Naam van de foto bevindt zich in de 4de kolom ==> index 3
            Dim kolom As DataGridViewCell = rij.Cells(3)
            ' Gebruik de naam van de foto om het pad samen te stellen

            Dim strFileName As String = ""
            If Not (IsNothing(kolom.Value)) AndAlso Not (IsDBNull(kolom.Value)) Then
                strFileName = kolom.Value.ToString()
            End If
            Dim strFullFileName As String = My.Settings.Productfotos & "\" & strFileName

            If File.Exists(strFullFileName) Then
                e.Value = Image.FromFile(strFullFileName)
            End If
        End If
    End Sub


End Class
